#pragma once
#include<iostream>
#include<vector>
#include"oj_model.hpp"
#include<ctemplate/template.h>
namespace ns_view
{
    using namespace ns_model;
    const std::string template_path ="./template_html/";
    class View
    {
        public:
        View()
        {}
        ~View()
        {}
        public:
        void AllExpendhtml(const vector<struct Question>&Questions,std::string*html)
        {
            //形成路径
            std::string src_html=template_path+"all_questions.html";
            //形成数字字典
            ctemplate::TemplateDictionary root("all_question");
            for(auto&q:Questions)
            {
                ctemplate::TemplateDictionary*sub=root.AddSectionDictionary("question_list");
                root.SetValue("number",q.number);
                root.SetValue("title",q.title);
                root.SetValue("star",q.star);
            }
            
            //获取被渲染的html
            ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            //开始完成渲染
            tpl->Expand(html,&root);
        }
        void OneExpendhtml(struct Question&q,std::string*html)
        {
            //形成路径
            std::string src_html=template_path+"one_questions.html";
            //形成数字字典
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number",q.number);
            root.SetValue("title",q.title);
            root.SetValue("star",q.star);
            root.SetValue("desc",q.desc);
            root.SetValue("pre_code",q.header);
            //获取被渲染的html
            ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            //开始完成渲染
            tpl->Expand(html,&root);
        }
    };
}